package com.feihong.txgw.utils.manage;

import com.feihong.txgw.http.Host;
import com.feihong.txgw.inter.retrofit_api.IRetrofitService;
import com.feihong.txgw.utils.client.TxokttpClient;

import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName RetrofitManager
 * @package com.feihong.txgw.utils.manage
 * @data 2018/5/2 11:01
 * @Describe
 * @Change
 */
public class RetrofitManager {

    private static final String baseUrl = Host.HTTP_HOME;
    private static Retrofit retrofit = null;
    private static IRetrofitService mRetrofitService;

    public static IRetrofitService getInstance() {
        if (retrofit == null) {
            synchronized (RetrofitManager.class) {
                if (retrofit == null) {
                    retrofit = new Retrofit.Builder()
                            .baseUrl(baseUrl)
                            .addConverterFactory(ScalarsConverterFactory.create())
                            .addConverterFactory(GsonConverterFactory.create())
                            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                            .client(TxokttpClient.create())
                            .build();
                    mRetrofitService = retrofit.create(IRetrofitService.class);
                }
            }
        }
        return mRetrofitService;
    }
}
